package com.xyazm.order.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xyazm.common.dao.BaseDAO;
import com.xyazm.order.domain.entity.OrderCancelScheduledTaskDO;
import com.xyazm.order.mapper.OrderCancelScheduledTaskMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 * 订单执行定时取消兜底任务DAO
 */
@Repository
@Slf4j
public class OrderCancelScheduledTaskDAO extends BaseDAO<OrderCancelScheduledTaskMapper, OrderCancelScheduledTaskDO> {

    /**
     * 保存订单任务记录
     */
    public boolean saveOne(String orderId, Date expireTime) {
        OrderCancelScheduledTaskDO orderCancelScheduledTaskDO = new OrderCancelScheduledTaskDO();
        orderCancelScheduledTaskDO.setOrderId(orderId);
        orderCancelScheduledTaskDO.setExpireTime(expireTime);
        return saveOrUpdate(orderCancelScheduledTaskDO);
    }

    /**
     * 根据订单号查询订单任务记录
     */
    public OrderCancelScheduledTaskDO getByOrderId(String orderId) {
        LambdaQueryWrapper<OrderCancelScheduledTaskDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OrderCancelScheduledTaskDO::getOrderId, orderId);
        return getOne(queryWrapper);
    }

    /**
     * 根据订单号删除订单任务记录
     */
    public boolean remove(String orderId) {
        LambdaQueryWrapper<OrderCancelScheduledTaskDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OrderCancelScheduledTaskDO::getOrderId, orderId);
        return remove(queryWrapper);
    }


}
